
<template>
  <div>
    <s-form-table :fields="fields"
                  ref="table"
                  :transformParams="transformParams"
                  :getData="getData"
                  :columns="columns">
    </s-form-table>
  </div>
</template>

<script>
import SFormTable from "@/components/SFormTable"
import api from "@/util/api";
import moment from "moment";
import { message } from "ant-design-vue";
export default {
  components: {
    SFormTable
  },
  filters: {},
  props: {},
  data () {
    return {
      detail: null,
      getUrl: "/api/order/getStatistics",
      title: "",
      fields: [
        {
          name: "time",
          showTime: false,
          width: 420,
          placeholder: ["开始时间", "结束时间"],
          type: "range"
        }
      ],
      columns: [
        {
          title: "",
          dataIndex: "name",
          width: "70px",
          fixed: "left",
          align: "center"
        },
        {
          title: "单数",
          dataIndex: "sum",
          align: "center"
        },
        {
          title: "小计(￥)",
          dataIndex: "total",
          align: "center"
        }
      ]
    };
  },
  watch: {
  },
  methods: {
    getData (val) {
      let params = {}
      if (val.time) {
        params.startDate = moment(val.time[0]).format("YYYY-MM-DD")
        params.endDate = moment(val.time[1]).format("YYYY-MM-DD")
      }
      return new Promise((resolve) => {
        api.get(`/api/order/getStatistics`, { params }).then(res => {
          if (res) {
            resolve({
              page: {
                total: 2
              },
              data: [
                {
                  name: "取消",
                  sum: res.data.cancel.sum,
                  total: res.data.cancel.total
                },
                {
                  name: "完成",
                  sum: res.data.complete.sum,
                  total: res.data.complete.total
                }
              ]
            })
          }
        });
      });
    },
    // 修改默认fields的参数（接口）
    transformParams (params) {
      params.rows = params.pageSize
      return params
    },
    refresh () {
      this.$refs.table.search();
    }
  }
};
</script>

<style lang="scss" scoped></style>
